#!/bin/bash
#. functions.sh

# Create the necessary tables/users for MySQL.
sudo /vagrant/vagrant/createdb.sh cmis cmis cmis 1>/dev/null

# Grant privileages for cmis #18268
mysql <<EOF
GRANT ALL PRIVILEGES ON *.* TO 'cmis'@'%' IDENTIFIED BY 'cmis';
FLUSH PRIVILEGES;
EOF

echo "--> Restart tomcat"
sudo sed -i -e '22s/8005/8105/' /etc/tomcat/server.xml
sudo sed -i -e 's/Connector port="8080"/Connector port="8180"/' /etc/tomcat/server.xml
sudo \cp /opt/cmis-server/chemistry-opencmis-server-jcr-1.0.0-SNAPSHOT.war /var/lib/tomcat/webapps/cmis.war

if [[ "$YUM_SYS" =~ ^7\..* ]]; then
sudo systemctl restart tomcat
fi

if [[ "$YUM_SYS" =~ ^6\..* ]]; then
sudo service tomcat restart
fi

if !(grep -q "mysql" /etc/hosts); then
  echo "127.0.0.1 mysql" >> /etc/hosts
fi
